package com.qch.concurrent.demo_03_callable;

import java.util.concurrent.*;

/**
 * @Author qch
 * @Date 2021/7/26
 */
public class MainPool {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        MyCallable myCallable = new MyCallable();
        ThreadPoolExecutor executor = new ThreadPoolExecutor(5, 5, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10)) {
            @Override
            protected void afterExecute(Runnable r, Throwable t) {
                //如果再call方法执行中有错误，则可以再次进行处理
               // super.afterExecute(r, t);
                System.out.println("任务执行完毕"+t);
            }
        };
        //通过执行器的submit传任务
        Future<String> future = executor.submit(myCallable);
        String s = future.get();
        System.out.println(s);
        executor.shutdown();
    }

}
